package com.ylb.rent.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ylb.rent.dao.ApartmentSecurityMapper;
import com.ylb.rent.entity.ApartmentFeetype;
import com.ylb.rent.entity.ApartmentSecurity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 import com.ylb.rent.dao.SecurityMapper;
import  com.ylb.rent.entity.Security;
import com.ylb.rent.service.ISecurityService;

/**
 * 安全保障Service业务层处理
 * 
 * @author ylb
 * @date 2023-06-29
 */
@Service
public class SecurityServiceImpl implements ISecurityService 
{
    @Autowired
    private SecurityMapper securityMapper;

    @Autowired
    ApartmentSecurityMapper apartmentSecurityMapper;

    @Override
    public List<Security> selectListByApartmentId(Long aId) {
        ApartmentSecurity selector = ApartmentSecurity.builder().apartmentId(aId).build();


        List<ApartmentSecurity> list = apartmentSecurityMapper.selectApartmentSecurityList(selector);
//        得到stuffId集合
        List<Long> idList = list.stream().map(ApartmentSecurity::getSecurityId).collect(Collectors.toList());
        return securityMapper.selectBatchIds(idList);
    }

    /**
     * 查询安全保障
     * 
     * @param id 安全保障主键
     * @return 安全保障
     */
    @Override
    public Security selectSecurityById(Long id)
    {
        return securityMapper.selectSecurityById(id);
    }

    /**
     * 查询安全保障列表
     * 
     * @param security 安全保障
     * @return 安全保障
     */
    @Override
    public List<Security> selectSecurityList(Security security)
    {
        return securityMapper.selectSecurityList(security);
    }

    /**
     * 新增安全保障
     * 
     * @param security 安全保障
     * @return 结果
     */
    @Override
    public int insertSecurity(Security security)
    {
        return securityMapper.insertSecurity(security);
    }

    /**
     * 修改安全保障
     * 
     * @param security 安全保障
     * @return 结果
     */
    @Override
    public int updateSecurity(Security security)
    {
        return securityMapper.updateSecurity(security);
    }

    /**
     * 批量删除安全保障
     * 
     * @param ids 需要删除的安全保障主键
     * @return 结果
     */
    @Override
    public int deleteSecurityByIds(Long[] ids)
    {
        return securityMapper.deleteSecurityByIds(ids);
    }

    /**
     * 删除安全保障信息
     * 
     * @param id 安全保障主键
     * @return 结果
     */
    @Override
    public int deleteSecurityById(Long id)
    {
        return securityMapper.deleteSecurityById(id);
    }
}
